package com.trkj.service.cf;

import java.sql.Timestamp;
import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;

import com.alibaba.fastjson.JSONArray;
import com.trkj.dao.cf.CertificateDAO;
import com.trkj.dao.cf.ZszlTypeDAO;
import com.trkj.mybatisdao.CertificateMappersDAO;
import com.trkj.pojo.Certificate;
import com.trkj.pojo.StaffInformation;
import com.trkj.pojo.ZszlType;
import com.trkj.service.ServiceException;
import com.trkj.vo.cf.CertificateVo;
import com.trkj.vo.cf.CourseVo;

@Service
@Transactional(rollbackFor=ServiceException.class)
public class CertificateService {
	@Autowired
	private CertificateDAO certificateDAO;
	@Autowired
	private ZszlTypeDAO zszlType;
	@Autowired
	private CertificateMappersDAO certificateMappersDAO;
	 
	//查询
	public JSONArray coursePage() throws ServiceException {
				try{
					return  certificateMappersDAO.queryBycertiName();
				} catch (Exception e) {
					e.printStackTrace();
					throw new ServiceException(e.getMessage());
				}
	}
	//新增
	public void Certificateadd(Long zszlId, String certiName, String certiOwnertype, String certiBorrowstate,
			String certiUsestate, Timestamp certiEffectivedate,HttpSession session)throws ServiceException {
				try{
						StaffInformation ff = (StaffInformation) session.getAttribute("staff");
				Certificate cer=new Certificate();
				cer.setZszlType(zszlType.findOne(zszlId));
				cer.setCertiName(certiName);
				cer.setCertiOwnertype(certiOwnertype);
				cer.setCertiBorrowstate(certiBorrowstate);
				cer.setCertiUsestate(certiUsestate);
				cer.setCertiEffectivedate(certiEffectivedate);
				cer.setCertiPerson(ff.getStainName());
				certificateDAO.save(cer);
				} catch (Exception e) {
					e.printStackTrace();
					throw new ServiceException(e.getMessage());
				}	
			}
				//删除
	        	public void certificateremove(Long certiId) {
	        		certificateDAO.delete(certiId);
	        	}

}
